package com.example.demo.model.base;

import com.example.demo.TypeEnum;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @author jie
 * @date 2021/1/22 -19:46
 */
public abstract class GenericModel implements IGenericModel {
    private String id;
    private String insertUser;
    //@Transient
    private String manualPrimaryKey;

    private final TypeEnum[] TYPE_ARRAY;


    protected GenericModel(TypeEnum... TYPE_ARRAY) {
        this.TYPE_ARRAY = TYPE_ARRAY;
        getEntity();
    }

    public void getEntity() {

        for (TypeEnum typeEnum : TYPE_ARRAY) {
            if (TypeEnum.INTERNATIONAL.equals(typeEnum)) {
                setNameCn("我是中文");
                setNameEn("I am english");

            }
        }

    }

    @Override
    public String generateId() {
        List<TypeEnum> typeEnums = Arrays.asList(TYPE_ARRAY);
        if (typeEnums.contains(TypeEnum.GUID)) {
           return UUID.randomUUID().toString();

        } else {
            return manualPrimaryKey;
        }
    }

    @Override
    public String getInsertUser() {
        return insertUser;
    }

    @Override
    public void setInsertUser(String insertUser) {
        this.insertUser = insertUser;
    }

    public TypeEnum[] getTYPE_ARRAY() {
        return TYPE_ARRAY;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getManualPrimaryKey() {
        return manualPrimaryKey;
    }

    public void setManualPrimaryKey(String manualPrimaryKey) {
        this.manualPrimaryKey = manualPrimaryKey;
    }
}
